package wt.hpad.model.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.ViewGroup;

import java.util.List;

import wt.hpad.R;
import wt.hpad.base.BaseHolder;
import wt.hpad.base.BaseRvSwAdapter;
import wt.hpad.model.bean.DishDetail;
import wt.hpad.model.holder.DishDetaiSwHolder;
import wt.hpad.model.holder.DishDetailNmHolder;

import static wt.hpad.ConstantFields.ITEM_TYPE_RETREAT;
import static wt.hpad.ConstantFields.ITEM_TYPE_SERVED;
import static wt.hpad.ConstantFields.ITEM_TYPE_SERVING;

/**
 * detail activity rv 对应适配器: 它又对应2个Holder
 * Created by wt on 12.25.
 */

public class DishDetailAdapter extends BaseRvSwAdapter<DishDetail> {

    private final Activity mActivty;

    public DishDetailAdapter(Activity activity, List<DishDetail> mDatas, Context context) {
        super(activity, mDatas, context);
        mActivty = activity;
    }

    @Override
    protected BaseHolder createViewHolder(Context context, ViewGroup parent, int viewType) {
        if (viewType == BaseRvSwAdapter.TYPE_NORMAL) {
            return new DishDetailNmHolder(context, parent, this, R.layout.item_dishdetail_normal);
        } else {
            DishDetaiSwHolder swHolder
                    = new DishDetaiSwHolder(context, parent, this, R.layout.item_dishdetail_swipe);
            swHolder.setActivity(mActivty);
            return swHolder;
        }
    }

    @Override
    protected int getItemType(int position) {
        int itemType = 0;
        DishDetail bean = getDatas().get(position);
        switch (bean.dishIsCompleted) {
            case ITEM_TYPE_SERVING:     // 未上
                itemType = BaseRvSwAdapter.TYPE_SWIPE;
                break;
            case ITEM_TYPE_SERVED:     // 已上
            case ITEM_TYPE_RETREAT:    // 已退
                itemType = BaseRvSwAdapter.TYPE_NORMAL;
                break;
        }
        return itemType;
    }

    @Override
    protected int getRId(int position) {
        return R.id.swipe_dishdetail;
    }
}
